package camid.util.monitoring;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;

public class JMeterClientLogger 
{
	private File logFile;
	private FileOutputStream fos;
	private PrintWriter printer;

	private static JMeterClientLogger INSTANCE;
	
	public synchronized static JMeterClientLogger getInstance()
	{
		if(INSTANCE == null)
		{
			INSTANCE = new JMeterClientLogger();
		}
		return INSTANCE;
	}
	
	private JMeterClientLogger()
	{
		try 
		{
			logFile = new File("camid-client.log");
			fos = new FileOutputStream(logFile);
			printer = new PrintWriter(fos, true);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	protected void finalize()
	{
		try {
			if(fos != null)
			{
				fos.close();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void info(String message)
	{
		if(printer != null)
		{
			Calendar cal = Calendar.getInstance();
			Integer hour = cal.get(Calendar.HOUR_OF_DAY);
			Integer minute = cal.get(Calendar.MINUTE);
			Integer second = cal.get(Calendar.SECOND);
			
			
			printer.printf("%02d:%02d:%02d - %s", hour, minute, second, message);
			printer.println();
		}
	}
}
